package com.zj.healthmanage.controller;

import com.zj.healthmanage.entity.PageResult;
import com.zj.healthmanage.entity.QueryPageBean;
import com.zj.healthmanage.entity.Result;
import com.zj.healthmanage.pojo.Checkgroup;
import com.zj.healthmanage.service.CheckgroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping(value = "/checkgroup")
@Api(value = "检查组",description = "检查组")
public class CheckGroupController {

    @Autowired
    private CheckgroupService checkgroupService;


    @ApiOperation(value = "新增检查组",httpMethod = "POST")
    @RequestMapping("/addCheckGroup")
    public Result addCheckGroup(@RequestBody Checkgroup checkGroup, Integer[] checkitemIdList){
        try{
            checkgroupService.insertSelective(checkGroup,checkitemIdList);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false, "新增检查组失败");
        }
        return new Result(true,"新增检查组成功");
    }

    @ApiOperation(value = "分页查询检查组",httpMethod = "POST")
    @RequestMapping("/queryCheckGroupByPage")
    public PageResult queryCheckGroupByPage(@RequestBody QueryPageBean queryPageBean){
        PageResult pageResult = checkgroupService.queryCheckGroupByPage(queryPageBean);
        return pageResult;
    }


    @ApiOperation(value = "查询单个检查组",httpMethod = "POST")
    @RequestMapping("/queryCheckGroupById")
    public Result queryCheckGroupById(Integer id){
        try{
            Checkgroup checkgroup = checkgroupService.selectByPrimaryKey(id);
            return new Result(true,"查询检查组成功",checkgroup);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false, "查询检查组失败");
        }
    }

    @ApiOperation(value = "查询所有检查组",httpMethod = "POST")
    @RequestMapping("/queryCheckGroup")
    public Result queryCheckGroup(){
        try{
            List<Checkgroup> list = checkgroupService.queryAll();
            return new Result(true,"查询检查组成功",list);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false, "查询检查组失败");
        }
    }


    @ApiOperation(value = "根据检查组id查包含的多给检查项id",httpMethod = "POST")
    @RequestMapping("/queryCheckItemIdsById")
    public Result queryCheckItemIdsByCheckGroupId(Integer id){
        try{
            List<Integer> checkitemList = checkgroupService.queryCheckItemIdsById(id);
            return new Result(true,"查询检查项成功",checkitemList);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false, "查询检查项失败");
        }
    }


    @ApiOperation(value = "删除检查组",httpMethod = "POST")
    @RequestMapping("/deleteCheckGroupById")
    public Result deleteCheckGroupById(Integer id){
        try {
            checkgroupService.deleteByPrimaryKey(id);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,"删除检查组失败");
        }
        return new Result(true,"删除检查组成功");
    }

    @ApiOperation(value = "编辑检查组",httpMethod = "POST")
    @RequestMapping("/editCheckGroup")
    public Result editCheckGroup(@RequestBody Checkgroup checkgroup,Integer[] checkitemIdList){
        try{
            checkgroupService.updateByPrimaryKeySelective(checkgroup,checkitemIdList);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false, "编辑检查组失败");
        }
        return new Result(true,"编辑检查组成功");
    }


}
